package com.qf.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.NewsDetail;
import com.qf.mapper.NewsDetailMapper;
import com.qf.service.NewsCommentService;
import com.qf.service.NewsDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author ASUS
 * @version V1.0
 * @Project work
 * @Package com.qf.service.impl
 * @Date 2021/10/5 13:41
 */
@Service
public class NewsDetailServiceImpl implements NewsDetailService {

    @Autowired
    private NewsDetailMapper newsDetailMapper;

    @Autowired
    private NewsCommentService newsCommentService;

    @Override
    public PageInfo<NewsDetail> findByPage(String content, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<NewsDetail> list = newsDetailMapper.findByPage('%'+content+'%');
        PageInfo<NewsDetail> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    @Transactional
    public void delete(long id) {
        newsDetailMapper.deleteByPrimaryKey(id);
        newsCommentService.delete(id);
    }
}
